﻿/************************************************************************
* Copyright (c) 2018 All Rights Reserved.
*命名空间：Common.Standard
*文件名： TimeHelper
*创建人： kingling
*创建时间：2018/9/27 17:33:47
*描述
*=======================================================================
*修改标记
*修改时间：2018/9/27 17:33:47
*修改人：kingling
*描述：
************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;

namespace Common.Standard
{
    public class TimeHelper
    {
        public static int TimeToSecondStamp(DateTime time)
        {
            return (int)(TimeZoneInfo.ConvertTimeToUtc(time) - TimeZoneInfo.ConvertTimeToUtc(new System.DateTime(1970, 1, 1))).TotalSeconds - 8 * 3600;
        }
        public static string TimeToMillisecondStamp(DateTime time)
        {
            return ((TimeZoneInfo.ConvertTimeToUtc(time) - TimeZoneInfo.ConvertTimeToUtc(new System.DateTime(1970, 1, 1))).TotalMilliseconds - 8 * 3600 * 1000).ToString();
        }
        /// <summary>
        /// 10位转时间
        /// </summary>
        /// <param name="stamp"></param>
        /// <returns></returns>
        public static DateTime SecondStampToTime(int stamp)
        {
            DateTime dtStart = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1));
            return new DateTime(1970, 1, 1).AddSeconds(stamp + 8 * 3600);
        }
    }
}
